//
//  AssetsView.m
//  AppleMarket
//
//  Created by yangy on 19/10/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "UnLoginAssetsView.h"

// ViewModel
#import "UnLoginViewModel.h"


@interface UnLoginAssetsView()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *tipsLabel;
@property (nonatomic, strong) UIButton *loginButton;
@property (nonatomic, strong) UnLoginViewModel *viewModel;

@end

@implementation UnLoginAssetsView
- (instancetype)initWithFrame:(CGRect)frame viewModel:(UnLoginViewModel*) viewModel
{
    self = [super initWithFrame:frame];
    if(self){
        [self addSubview:self.titleLabel];
        [self addSubview:self.tipsLabel];
        [self addSubview:self.loginButton];
        
        // 未登录显示登录按钮
        // 登录过显示用户资产
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(15);
            make.bottom.mas_equalTo(self.mas_centerY).offset(-5);
        }];
        
        [_tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(15);
            make.top.mas_equalTo(self.mas_centerY).offset(5);
        }];
        
        [_loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self).offset(-13);
            make.centerY.mas_equalTo(self);
        }];
        
        _viewModel = viewModel;
    }
    return self;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel){
        _titleLabel = [UILabel cm_labelWithText:@"我的资产" font:kFontBold(16) textColor:kColorWithHex(0x0E304C)];
    }
    return _titleLabel;
}

- (UILabel *)tipsLabel
{
    if(!_tipsLabel){
        _tipsLabel = [UILabel cm_labelWithText:@"登录后可查看" font:kFont(13) textColor:kColorWithHex(0xADB7C1)];
    }
    return _tipsLabel;
}

- (UIButton *)loginButton
{
    if(!_loginButton){
        _loginButton = [UIButton cm_ButtonWithTitle:@"登录" font:kFont(15) titleColor:kColorWithHex(0x3291EB)];
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"home_login_bg"] forState:UIControlStateNormal];
        [_loginButton setTitleEdgeInsets:UIEdgeInsetsMake(-8, 0, 0, 0)];
        @weakify(self);
        [[_loginButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [self.viewModel.loginSubject sendNext:nil];
        }];
    }
    return _loginButton;
}


@end
